<!DOCTYPE  HTML>
<html>
	<head>
		
		<meta charset="utf-8">
  		<meta name="viewport" content="width=device-width, initial-scale=1">
  		<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
		<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  		<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
		<link rel="stylesheet" href="../resources/style.css" />
		<script type="text/javascript" src="../resources/script.js"></script>
		<script>
			 function setComment(u_id , s_id)
			{
				var ans = prompt("Enter the reason for rejecting the session","");
			
				location.assign('home_user.php?user_id='+u_id+'&sess_id='+s_id+'&status=rejected&reason='+ans,'_SELF');
			}
		</script>
	</head>
	<body>
	<?php
		if((array_key_exists('user_id' , $_GET)) && (array_key_exists('sess_id' , $_GET)) && (array_key_exists('status' , $_GET)))
		{
			$user_id = $_GET['user_id'];
			$sess_id = $_GET['sess_id'];
			$reason  = $_GET['reason'];
			$conn = new mysqli('localhost', 'root', 'root123', 'tms');
			$status = $_GET['status'];
			$sql  = "update User_Session set status = '".$status."', reason = '".$reason."' where user_id = ".$user_id." and sess_id = ".$sess_id;
			$conn->query($sql);
		}
	
		
		
	?>		
	<div id="ahmainpnl" >
			<img id="ahlogo" src="../resources/logo.png"></img>
			<div id="ahheaderpnl">
				
				<p id="hSess">My Sessions</p>
			</div>
			<div id="ahmenupnl">
				 <a href="home_user.php" id="ahbtnhome" class="btn btn-success">Home</a>
				
				<hr/>
				<a href="#" id="ahbtnhome" class="btn btn-info">Profile</a>
				<a id="ahbtnhome" class="btn btn-info" href="../login.html">Logout</a>
			</div>
			<div id="ahcontentpnl">
				<div class="container">
  
<!--button id="btnMySession" type="button"  class="btn btn-primary" data-toggle="collapse" data-target="#addMySes" ></button-->
         		</div>
	<h2><div class="alert alert-success" id="AcceptedMSG"></div></h2>
			
			
			
				<div id="divMySes" class="container">
					<table class="table table-hover">
						<thead>
							<tr>
								<th>ID</th>
	        						<th>Name</th>
	        						<th>Date</th>
								<th>Time</th>
 								<th>Trainer</th>
								<th>Technology</th>
								<th id="uhstatus"> Session Status</th>
								<th>MyStatus</th>
								<th>Option</th>
      							</tr>
						</thead>
						<tbody class="tbody">
							<?php
								$conn = new mysqli('localhost', 'root', 'root123', 'tms');
								$user_id = $_GET['user_id'];

								$sql  = "select Profile.user_id,Training_Session.sess_id, User_Session.status, Training_Session.sess_name, Training_Session.sess_status, Training_Session.on_date, Training_Session.start_time, Training_Session.trainer, Technology.tech_title, Training_Session.sess_status from User, Training_Session, User_Session, Technology, Profile where User.user_id = User_Session.user_id and Training_Session.sess_id = User_Session.sess_id and Technology.tech_id = Training_Session.tech_id and Profile.user_id = User.user_id and User.user_id = ".$user_id;
							
								$res = $conn->query($sql);
								
								if($res->num_rows != 0)
								{
									while($row = $res->fetch_assoc())
									{
										if($row['sess_status'] == 'postponed')
										{
							?>
							<tr  id="rowselect" class="info"> <!--onload="funSessStatus()"-->
								<td><?php print $row['user_id']; ?></td>
						        	<td id="sesnm1"><?php print $row['sess_name']; ?></td>
						       		<td><?php print $row['udate']; ?></td>
								<td><?php print $row['start_time']; ?></td>
								<td><?php print $row['trainer']; ?></td>
								<td><?php print $row['tech_title']; ?></td>
								<td id="SessStatus"><?php print $row['sess_status']; ?></td>
								<td>
									<?php
										print $row['status'];
									?>
								</td>
								<td>
									<div id="divAcceptReject"> 
										<button type="button" id="btnaccept" class="btn btn-default btn-info"  onclick="window.open('home_user.php?user_id=<?php print $row['user_id'];?>&sess_id=<?php print $row['sess_id']; ?>&status=accepted','_self')">
										<span class="glyphicon glyphicon-ok">
										</span>
										Accept	
										</button>
										<button type="button" id="btnreject" class="btn btn-default btn-info" data-toggle="collapse" data-target="#Comment" onclick="setComment(<?php print $row['user_id']; ?> , <?php print $row['sess_id'];?>)">		
										<span class="glyphicon glyphicon-remove" >													Reject
										</span>
											
										</button>
										<div id="Comment" class="collapse container">
											<textarea  id="txtareacomment" rows="4" cols="25" placeholder="Reason for not attending">
											</textarea>
											<span id="commentDone" class="glyphicon glyphicon-ok-circle">
											</span>
											
										</div>
									</div>
								</td>
		
							</tr>
							<?php
										}
										elseif($row['sess_status'] == 'available')
										{
							?>

							<tr  id="rowselect" class="success">
								 <td><?php print $row['user_id']; ?></td>
                                                                <td id="sesnm1"><?php print $row['sess_name']; ?></td>
                                                                <td><?php print $row['udate']; ?></td>
                                                                <td><?php print $row['start_time']; ?></td>
                                                                <td><?php print $row['trainer']; ?></td>
                                                                <td><?php print $row['tech_title']; ?></td>
                                                                <td id="SessStatus"><?php print $row['sess_status']; ?></td>
								 <td>
                                                                        <?php
                                                                                print $row['status'];
                                                                        ?>
                                                                </td>
                                                                <td>
                                                                        <div id="divAcceptReject">
                                                                                <button type="button" id="btnaccept" class="btn btn-default btn-info"  onclick="window.open('home_user.php?user_id=<?php print $row['user_id'];?>&sess_id=<?php print $row['sess_id']; ?>&status=accepted','_self')">
                                                                                <span class="glyphicon glyphicon-ok">
                                                                                </span>
                                                                                Accept
                                                                                </button>
                                                                                <button type="button" id="btnreject" class="btn btn-default btn-info" onclick="setComment(<?php print $row['user_id']; ?> , <?php print $row['sess_id'];?>)">
                                                                                <span class="glyphicon glyphicon-remove" >                                                                                                      Reject
                                                                                </span>

                                                                                </button>
                                                                                <div id="Comment" class="collapse container">
                                                                                        <textarea  id="txtareacomment" rows="4" cols="25" placeholder="Reason for not attending">
                                                                                        </textarea>
                                                                                        <span id="commentDone" class="glyphicon glyphicon-ok-circle">
                                                                                        </span>

                                                                                </div>
                                                                        </div>
                                                                </td>
							</tr>
							<?php
										}
										else
										{
							?>
							<tr  id="rowselect" class="danger">
								 <td><?php print $row['user_id']; ?></td>
                                                                <td id="sesnm1"><?php print $row['sess_name']; ?></td>
                                                                <td><?php print $row['udate']; ?></td>
                                                                <td><?php print $row['start_time']; ?></td>
                                                                <td><?php print $row['trainer']; ?></td>
                                                                <td><?php print $row['tech_title']; ?></td>
                                                                <td id="SessStatus"><?php print $row['sess_status']?></td>
							</tr>
							<?php
										}
									}
								}
								else
								{
									echo "you are not assigned to any sessions";
								}
							?>	
						</tbody>
  					</table>
				
				</div>
			
		</div>
		<div class="divfooter" >
			<p>© 2007-2015 Spring Computing Technologies Pvt. Ltd., All Rights Reserved.</p>
		</div>
	</body>
	
</html>
